#! /usr/bin/env/python3
# _*_ coding:UTF-8 _*_
'''
    map
    作者：
    日期：2020/02/29
'''
from functools import reduce


def f(x):
    return x * x


r = map(f, range(1, 10))
print(r)
print(list(r))
# 采用循环：
L = []
for n in range(1, 10):
    L.append(f(n))
print(L)

print(list(map(str, range(1, 10))))
# 采用for循环
L = []
for n in range(1, 10):
    L.append(str(n))
print(L)


def add(x, y):
    return x + y


print(reduce(add, range(1, 11)))


def fn(x, y):
    return x * 10 + y


def char2num(s):
    digits = {'0': 0, '1': 1, '2': 2, '3': 3, '4': 4, '5': 5, '6': 6, '7': 7, '8': 8, '9': 9}
    return digits[s]


print(input('123:'))
print(reduce(fn, map(char2num, input('123:'))))

DIGITS = {'0': 0, '1': 1, '2': 2, '3': 3, '4': 4, '5': 5, '6': 6, '7': 7, '8': 8, '9': 9}


def str2int(s):
    def fn(x, y):
        return x * 10 + y

    def char2num(s):
        return DIGITS[s]

    return reduce(fn, map(char2num, s))


print(str2int('1'))


def char2num2(s):
    '''
    数字字符串list 转为int型list
    '''
    return DIGITS[s]


def str2int2(s):
    return reduce(lambda x, y: x * 10 + y, map(char2num2, s))


print(str2int2('12'))


def normalize(name):
    L = ''
    L += (str.upper(name[0]))
    for x in range(1, len(name)):
        L += (str.lower(name[x]))
    return str(L)


name_list = ['adam', 'LISA', 'barT']
normalize_name_list = list(map(normalize, name_list))
print(normalize_name_list)


# 利用reduce函数就list的乘积
def pord(int_list):
    return reduce(lambda x, y: x * y, int_list)


str_input = input('请输入几个数，并用空格隔开：')
str_list = str_input.strip().split(' ')
int_list = list(map(str2int2, str_list))
print(int_list)
chengji = pord(int_list)
print(chengji)


def str2flaot(float_str_list):
    s = float_str_list.strip().split('.')
    int_str_list = list(s[0])
    print(int_str_list)
    flaot_s_list = list(s[1])
    print(flaot_s_list)
    _int = reduce(lambda x, y: x * 10 + y, list(map(str2int2, s[0])))
    flaot_s_list.reverse()
    f = list(map(char2num2, flaot_s_list))
    _float = reduce(lambda x, y: x / 10 + y, f) / 10
    num = _int + _float
    return num


float_str_input = input('请输入flaot:')
print('输入的：' + float_str_input + '是：', type(float_str_input))
_float = str2flaot(float_str_input)
print('输出的:{}是{}'.format(_float, type(_float)))
